package x.ovo.wechat.bot.http.request.message;

import cn.hutool.core.net.url.UrlBuilder;
import x.ovo.wechat.bot.common.Constant;
import x.ovo.wechat.bot.common.http.request.ApiRequest;
import x.ovo.wechat.bot.common.http.session.LoginSession;

import java.util.function.Function;

/**
 * 获取视频请求
 *
 * @author ovo on 2024/05/06.
 * @since 1.0.0
 */
public class GetVideoRequest extends ApiRequest<byte[]> {

    private final Long mediaId;

    public GetVideoRequest(LoginSession session, Long mediaId) {
        super(session);
        this.mediaId = mediaId;
    }

    @Override
    public String getUrl() {
        String build = UrlBuilder.of(this.session.getUrl())
                .addPath(Constant.GET_VIDEO)
                .addQuery("MsgID", mediaId)
                .addQuery("skey", this.session.getSKey())
                .build();
        super.addHeader("Referer", build)
                .addHeader("Range", "bytes=0-");
        return build;
    }

    @Override
    public Function<String, byte[]> responseHandler() {
        return String::getBytes;
    }
}
